<?


require_once("include.php");

$me=false;
require_once("header.session.php");
require_once("header.gui.php");
require_once("header.misc.php");


//globals
$MenuObjects= $me->getMyMenu();



if(!$me) {
	$me=&new Person($_SESSION['id']);
}

if(!isset($_GET['group'])) {
	$_GET['group']="default";
}
if(!isset($_GET['day'])) {
	$_GET['day']=unixToDate(time());
}
if(unixToDate(timestampToUnix($_GET['day']))!=$_GET['day']) {
	$_GET['day']=unixToDate(time());
}

if(isset($_GET['action'])) {
	$extraurl="";
	switch($_GET['action']) {
		case "changedate":
			$_GET['day']=$_GET['year']."-".$_GET['month']."-01";
			break;
	}
	header("Location: " . $_SERVER['PHP_SELF'] . "?group=" . $_GET['group'] . "&day=" . $_GET['day'] . $extraurl);
	die;
}


function Headers() {
	
}
function Body() {
	global $me;
	echo "
	<b>Current Date:</b> " . $_GET['day'] . "<br>
	<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"get\">
		<input type=\"hidden\" name=\"day\" value=\"" . $_GET['day'] . "\">
		<input type=\"hidden\" name=\"group\" value=\"" . $_GET['group'] . "\">
		<input type=\"hidden\" name=\"action\" value=\"changedate\">
		Month(MM): <input type=\"text\" name=\"month\">
		<br>
		Year(YYYY): <input type=\"text\" name=\"year\">
		<br>
		<input type=\"submit\">
	</form>
	P=Present<br>
	T=Tardy<br>
	A=Absent<br>
	Green=Excused<br>
	Red=Unexcuse<br>
	<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
	<tr><td><small><b>NAME</b></small></th>
	";
	for($i=0;$i<30;$i++) {
		if(!(dayOfWeek(unixToTimestamp(timestampToUnix($_GET['day'])+(24*60*60*$i)))=="Saturday" OR dayOfWeek(unixToTimestamp(timestampToUnix($_GET['day'])+(24*60*60*$i)))=="Sunday")) {
		echo "
			<td><small>" . date("m-d",(timestampToUnix($_GET['day'])+(24*60*60*$i))) . "</small></td>";
		}
	}
	echo "</tr>
	";
	$users=getUserList("");
	$tardy="T";
	$absent="A";
	$present="P";
	$dismiss="D";
	$excused="#00FF00";
	$unexcused="#FF0000";
	foreach($users as $val) {
		if(isStudent($val['people_id'])) {
			echo "<tr><td>" . stripslashes($val['people_lastname']) . ", " . stripslashes($val['people_firstname']) . "
			</td>";
			for($i=0;$i<30;$i++) {
				$today=explode(":",getAttendance($val['people_id'],unixToTimestamp(timestampToUnix($_GET['day'])+(24*60*60*$i))));
				if(!(dayOfWeek(unixToTimestamp(timestampToUnix($_GET['day'])+(24*60*60*$i)))=="Saturday" OR dayOfWeek(unixToTimestamp(timestampToUnix($_GET['day'])+(24*60*60*$i)))=="Sunday")) {
				echo "
					<td style=\"background-color:" . $$today[1] . "\">" . $$today[0] . "</td>";
				}
			}
			echo "</tr>";
		}
	}
	
	
	echo "</table>";
}

require_once("template.php");
		